def dfs(s):
    if s == m + 1:
        print(b[1:m+1])
    else:
        for i in range(1, n + 1):
            if vis[i] == 0:
                vis[i] = 1
                b[s] = a[i]
                dfs(s + 1)
                vis[i] = 0

n, m = list(map(int,input().split()))
# a = [0] * 10
# b = [0] * 10
vis = [0] * 10
# for i in range(1, n + 1):
#     a[i] = i
a = list(range(10))
b = list(range(10))
dfs(1)
